package com.zj.framework.excel.test;

import com.alibaba.fastjson.JSON;
import com.zj.framework.baseto.type.DatePattern;
import com.zj.framework.excel.ExcelUtil;
import com.zj.framework.utils.ZjDateUtils;
import org.junit.Test;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * @author xi.yang(xi.yang@downjoy.com)
 * @create 2018-05-28 下午 4:28
 **/
public class OrderExcel {
    @Test
    public void dd() throws Exception {
        List<Map<String, Object>> list = ExcelUtil.getExcel2Maps("C:\\Users\\Administrator\\Desktop\\order.xlsx", 0);
        File fout = new File("C:\\Users\\Administrator\\Desktop\\orders.txt");
        FileOutputStream fos = new FileOutputStream(fout);
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));

        for (Map<String, Object> map : list) {
            map.put("__dctime", ZjDateUtils.formatDateTime( ZjDateUtils.parseDate(map.get("created_date").toString()), DatePattern.yyyyMMdd));
            map.put("type",1);
            map.put("channel_name",""+new BigDecimal(map.get("channel_id").toString()).longValue());
            map.put("channel_id",new BigDecimal(map.get("channel_id").toString()).longValue());
            map.put("pc_id",new BigDecimal(map.get("pc_id").toString()).longValue());
            map.put("app_name",""+new BigDecimal(map.get("app_id").toString()).longValue());
            map.put("pc_name","折扣app充值");
            map.put("app_id",new BigDecimal(map.get("app_id").toString()).longValue());
            map.put("mid",new BigDecimal(map.get("mid").toString()).longValue());
            map.put("money",new BigDecimal(map.get("money").toString()).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
            map.put("msgid-inbus", UUID.randomUUID().toString().replace("-",""));
            map.put("charge_money",new BigDecimal(map.get("charge_money").toString()).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
            bw.write(JSON.toJSONString(map));
            bw.newLine();
        }

        bw.close();
    }
}
